import { ApiProperty, IntersectionType, PartialType } from '@nestjs/swagger';
import {
  IsArray,
  IsEnum,
  IsIn,
  IsInt,
  IsOptional,
  IsString,
  Matches,
  MinLength,
} from 'class-validator';

import { PagerDto } from '~/common/dto/pager.dto';
import { RoleValueEnum } from './role.entity';
import { CommonStatus } from '~/common/entity/common.entity';

export class RoleDto {
  @ApiProperty({ description: '角色名称', required: true, default: '用户1' })
  @IsString()
  @MinLength(2, { message: '角色名称长度不能小于2' })
  name: string;

  @ApiProperty({
    description: '角色值',
    required: true,
    default: RoleValueEnum.USER,
    enum: RoleValueEnum,
  })
  @IsEnum(RoleValueEnum, { message: '角色值不正确' })
  value: RoleValueEnum;

  @ApiProperty({ description: '角色备注', default: '' })
  @IsString()
  @IsOptional()
  remark?: string;

  @ApiProperty({
    description: '状态',
    required: true,
    default: CommonStatus.YES,
    enum: CommonStatus,
  })
  @IsEnum(CommonStatus, { message: '状态不正确' })
  status: CommonStatus;
}

export class RoleBindDto {
  @ApiProperty({ description: '角色ID', required: true, default: 0 })
	@IsInt()
  roleId: number;

  @ApiProperty({ description: '用户ID', required: true, default: 0 })
  @IsInt()
  userId: number;
}

export class RoleUpdateDto extends PartialType(RoleDto) {}

export class RoleQueryDto extends IntersectionType(PagerDto<RoleDto>, PartialType(RoleDto)) {
  // @ApiProperty({ description: '角色名称', required: false })
  // @IsString()
  // name?: string;
  // @ApiProperty({ description: '角色值', required: false })
  // @IsString()
  // value: string;
}
